import 'package:flutter/material.dart';

class RichTextPage extends StatefulWidget {
  @override
  _RichTextPageState createState() => _RichTextPageState();
}

class _RichTextPageState extends State<RichTextPage> {
  double size = 50;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('rich text page'),
        actions: <Widget>[
          IconButton(
            icon: Icon(Icons.add_circle_outline),
            onPressed: () {
              setState(() {
                size += 10;
              });
            },
          ),
          IconButton(
            icon: Icon(Icons.remove_circle_outline),
            onPressed: () {
              setState(() {
                size -= 10;
              });
            },
          ),
        ],
      ),
      body: Container(
        margin: EdgeInsets.all(10.0),
        child: Text.rich(
          TextSpan(
            children: <InlineSpan>[
              TextSpan(text: 'Flutter is'),
              WidgetSpan(
                  child: SizedBox(
                width: 120,
                height: 50,
                child: Card(
                    color: Colors.blue,
                    child: Center(child: Text('Hello World!'))),
              )),
              WidgetSpan(
                child: SizedBox(
                  width: size > 0 ? size : 0,
                  height: size > 0 ? size : 0,
                  child: Image.asset(
                    "images/my-img.jpg",
                    fit: BoxFit.cover,
                  ),
                ),
              ),
              TextSpan(text: 'the best!'),
            ],
          ),
        ),
      ),
    );
  }
}
